package com.egao.common.module.cms.controller;

import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.core.web.PageParam;
import com.egao.common.core.web.PageResult;
import com.egao.common.module.cms.entity.SelectedColumn;
import com.egao.common.module.cms.entity.SelectedColumn;
import com.egao.common.module.cms.entity.vo.SelectedColumnListVO;
import com.egao.common.module.cms.service.SelectedColumnService;
import com.egao.common.module.cms.service.SelectedColumnService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * (SelectedColumn)表控制层
 *
 * @author makejava
 * @since 2021-04-26 13:50:36
 */
@RestController
@RequestMapping("${api}")
public class SelectedColumnController extends BaseController {

    @Autowired
    private SelectedColumnService selectedColumnService;

    @PreAuthorize("hasAuthority('cms:selectedcolumn:list')")
    @ApiOperation("分页查询选调专栏")
    @OperLog(value = "选调专栏管理", desc = "分页查询选调专栏")
    @GetMapping("/cms/selected-column/page")
    public PageResult<SelectedColumnListVO> page(HttpServletRequest request) {
        PageParam<SelectedColumnListVO> pageParam = new PageParam<>(request);
        return new PageResult<>(selectedColumnService.listPage(pageParam),pageParam.getTotal());
    }

    @PreAuthorize("hasAuthority('cms:selectedcolumn:insert')")
    @ApiOperation("添加选调专栏")
    @OperLog(value = "选调专栏管理", desc = "添加选调专栏", result = true)
    @PostMapping("/cms/selected-column/insert")
    public JsonResult insert(@RequestBody SelectedColumn selectedColumn) {
        selectedColumn.setCreateBy(getLoginUserId());
        return selectedColumnService.insertSelectedColumn(selectedColumn);
    }

    @PreAuthorize("hasAuthority('cms:selectedcolumn:update')")
    @ApiOperation("修改选调专栏")
    @OperLog(value = "选调专栏管理", desc = "修改选调专栏", result = true)
    @PutMapping("/cms/selected-column/update")
    public JsonResult update(@RequestBody SelectedColumn selectedColumn) {
        return selectedColumnService.updateSelectedColumn(selectedColumn);
    }

    @PreAuthorize("hasAuthority('cms:selectedcolumn:delete')")
    @ApiOperation("删除选调专栏")
    @OperLog(value = "选调专栏管理", desc = "删除选调专栏", result = true)
    @DeleteMapping("/cms/selected-column/delete")
    public JsonResult delete(Integer id) {
        return selectedColumnService.deleteSelectedColumn(id);
    }


    @PreAuthorize("hasAuthority('cms:selectedcolumn:detail')")
    @ApiOperation("查询单个选调专栏")
    @OperLog(value = "选调专栏管理", desc = "查询单个选调专栏")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "选调专栏id", required = false, dataType = "Integer", paramType = "query"),
    })
    @GetMapping("/cms/selected-column/get")
    public JsonResult listGetId(Integer id) {
        return selectedColumnService.getId(id);
    }
}
